package com.shengde.jinwawaforleader.network;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.shengde.jinwawaforleader.HomeApplication;
import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.bean.TeacherFlagInAllClass;
import com.shengde.jinwawaforleader.bean.User;
import com.shengde.jinwawaforleader.model.myJob.adapter.FoodExpandableListAdapter;
import com.shengde.jinwawaforleader.model.myJob.classList.AddTeacherActivity;
import com.shengde.jinwawaforleader.model.myJob.classList.ChangeStuClass;
import com.shengde.jinwawaforleader.model.myJob.classList.ChangeTeacherActivity;
import com.shengde.jinwawaforleader.model.myJob.classList.ClassDetailsActivity;
import com.shengde.jinwawaforleader.model.myJob.classList.ClassListActivity;
import com.shengde.jinwawaforleader.model.myJob.classList.ModifyStudentInfo;
import com.shengde.jinwawaforleader.model.myJob.classList.ModifyTeacherInfo;
import com.shengde.jinwawaforleader.model.myJob.everyRecipe.EveryRecipeActivity;
import com.shengde.jinwawaforleader.model.myJob.everyRecipe.MenuToAddActivity;
import com.shengde.jinwawaforleader.model.myJob.everyRecipe.ModifyTheMenuActivity;
import com.shengde.jinwawaforleader.model.myJob.fragment.AllClassFragment;
import com.shengde.jinwawaforleader.model.myJob.fragment.AllTeacherFragment;
import com.shengde.jinwawaforleader.model.myJob.instance_message.Constant;
import com.shengde.jinwawaforleader.model.myJob.teachResource.MingshiDetailActivity;
import com.shengde.jinwawaforleader.model.myJob.teachResource.MingshiShipinListActivity;
import com.shengde.jinwawaforleader.model.myJob.teachResource.TeachDataActivity;
import com.shengde.jinwawaforleader.network.protocolbean.ProAllClassOfSchool;
import com.shengde.jinwawaforleader.network.protocolbean.ProAssignTeaStuList;
import com.shengde.jinwawaforleader.network.protocolbean.ProBaseRequestInfo;
import com.shengde.jinwawaforleader.network.protocolbean.ProBookList;
import com.shengde.jinwawaforleader.network.protocolbean.ProBumenList;
import com.shengde.jinwawaforleader.network.protocolbean.ProChapterList;
import com.shengde.jinwawaforleader.network.protocolbean.ProClassList;
import com.shengde.jinwawaforleader.network.protocolbean.ProEveryRecipe;
import com.shengde.jinwawaforleader.network.protocolbean.ProFoodTypeInfo;
import com.shengde.jinwawaforleader.network.protocolbean.ProStudentInfo;
import com.shengde.jinwawaforleader.network.protocolbean.ProTeacherInfo;
import com.shengde.jinwawaforleader.network.protocolbean.ProVideoList;
import com.shengde.jinwawaforleader.utils.MessageEvent;

import org.greenrobot.eventbus.EventBus;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class BaseProtocol {
    private static final String TAG = "BaseProtocol";

    //更新用户device token接口
    public static final String HOST_BASE = "https://www.kingvar.com/api";
    public static final String HOST_BASE_TEST = "http://120.76.155.123:8080/api";
    //图片地址
    public static final String IMG_BASE = "https://www.kingvar.com/uploads/";

    //视频第一帧图片地址
    public static final String IMG_FRIST_BASE = "https://www.kingvar.com:8083/mvimg/";

    //播放视频地址
    public static final String VIDEO_BASE = "https://www.kingvar.com:8083/mv/";

    //分享视频
    public static final String VIDEO_SHARE = "http://www.kingvar.com/soldiery/video.htm?vid="; //分享视频的地址

    //分享相册
    public static final String IMG_SHARE = "http://www.kingvar.com/soldiery/photos.htm?albumid="; //分享相册图片的地址

    public static final String IMG_UPLOAD_HOST = "https://www.kingvar.com:8083/api/parent/ImageUpload"; //上传图片

    //加载学校风采的h5
    public static final String SCHOOL_MIEN = "http://www.kingvar.com/soldiery/website.htm?schoolid=";

    private static BaseProtocol instance;

    private BaseProtocol() {
    }

    public static BaseProtocol getInstance() {
        if (instance == null) {
            instance = new BaseProtocol();
        }
        return instance;
    }

    /**
     * 为了添加请求头
     *
     * @param url
     * @return
     */
    public static RequestParams getRequestParams(String url) {
        RequestParams params = new RequestParams(url);
        params.addHeader("userid", User.getUserLoginAccount(HomeApplication.applicationContext));
        params.addHeader("mytype", "3");
        params.addHeader("myos", "Android");
        params.addHeader("mycode", User.getMyCode(HomeApplication.applicationContext));
        params.setCacheMaxAge(1000 * 60);
        return params;
    }

    /**
     * 食谱接口:每天食谱类型获取
     *
     * @param activity
     */
    public void getFoodType(final MenuToAddActivity activity) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/recipes/recipesTypes" + "?schoolid=" + User.getSchoolId(activity.getApplication()));

        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProFoodTypeInfo info = new Gson().fromJson(result, ProFoodTypeInfo.class);
                if (info.getCode() == 0) {
                    activity.foodType = info.getType();
                    activity.handler.sendEmptyMessage(activity.GET_FOOD_TYPE);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 食谱接口：添加
     *
     * @param activity
     */
    public void addRecipe(final MenuToAddActivity activity, String path) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/recipes/recipesPublish");

        params.addParameter("schoolid", User.getSchoolId(activity.getApplication()));
        params.addParameter("title", activity.string2);
        params.addParameter("content", activity.content);
        params.addParameter("date", activity.date);
        params.addParameter("img", path);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo requestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                Log.i(TAG, "onSuccess: code = " + requestInfo.getCode());
                if (requestInfo != null && requestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("上传成功!");
                    activity.fileList.clear();
                    activity.setResult(Constant.REFRESH_ADAPTER);
                    activity.finish();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.i(TAG, "onError: ex = " + ex);
                HomeApplication.showToastShort("上传失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 食谱接口：删除
     *
     * @param adapter
     * @param groupPosition
     * @param childPosition
     * @param dialog
     */
    public void delRecipe(Context context, final FoodExpandableListAdapter adapter, int groupPosition, int childPosition, final DialogInterface dialog) {

        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/recipes/recipesDelete");

        params.addParameter("id", adapter.parentList.get(groupPosition).getGifted().get(childPosition).getId());
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo info = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (info != null && info.getCode() == 0) {
                    HomeApplication.showToastShort("删除成功!");
                    dialog.dismiss();
                    Intent mIntent = new Intent(adapter.activity, EveryRecipeActivity.class);
                    adapter.activity.startActivity(mIntent);
                    adapter.activity.finish();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 食谱接口：获取一周食谱
     *
     * @param week
     */
    public void changeWeek(String week, final EveryRecipeActivity activity) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/recipes/recipesList");

        params.addParameter("week", week);
        params.addParameter("schoolid", User.getSchoolId(activity.getApplication()));
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProEveryRecipe recipe = new Gson().fromJson(result, ProEveryRecipe.class);
                if (recipe != null && recipe.getCode() == 0) {
                    activity.list.clear();
                    activity.list.addAll(recipe.getData());
                    activity.updateData();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 食谱接口：修改
     *
     * @param imgpath
     */
    public void modifyRecipe(String imgpath, final ModifyTheMenuActivity activity) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/recipes/recipesUpdate");

        params.addParameter("schoolid", User.getSchoolId(activity.getApplication()));
        params.addParameter("img", imgpath);
        params.addParameter("title", activity.title);
        params.addParameter("content", activity.string1);
        params.addParameter("date", activity.date);
        params.addParameter("id", activity.id);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo requestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (requestInfo != null && requestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("修改成功");
                    activity.setResult(Constant.REFRESH_ADAPTER);
                    activity.finish();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 名师备课:书本章节列表获取接口
     *
     * @param activity
     */
    public void getChapterList(final MingshiDetailActivity activity) {
        String url = "http://www.jollyclass.com/case/partner/list";
        RequestParams params = BasexUtilsProtocol.sendGetHttpRequest(activity, url);

        params.addParameter("bookId", "" + activity.Id);
        params.addParameter("pnum", "30");
        params.addParameter("page", "1");
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProChapterList list = new Gson().fromJson(result, ProChapterList.class);
                if (list != null) {
                    activity.list = list.getCaselist();
                    activity.updateData();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 名师备课:书本列表的获取接口
     *
     * @param activity
     */
    public void getBookList(final TeachDataActivity activity) {
        String url = "http://www.jollyclass.com/case/books";
        RequestParams params = BasexUtilsProtocol.sendGetHttpRequest(activity, url);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBookList list = new Gson().fromJson(result, ProBookList.class);
                if (list != null) {
                    activity.parseData(list);
                    activity.displayPage(0);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 名师备课:示范课视频列表获取接口
     *
     * @param activity
     */
    public void getVideoList(final MingshiShipinListActivity activity) {
        String url = "http://www.jollyclass.com/article/partner/list";
        RequestParams params = BasexUtilsProtocol.sendGetHttpRequest(activity, url);

        params.addParameter("pnum", "30");
        params.addParameter("page", "1");
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProVideoList list = new Gson().fromJson(result, ProVideoList.class);
                if (list != null) {
                    activity.list = list.getDataList();
                    activity.updateData();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 班级列表接口
     *
     * @param activity
     */
    public void postClassList(final ClassListActivity activity, final AllClassFragment classFragment, final AllTeacherFragment teacherFragment) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/classList");

        params.addParameter("schoolid", User.getSchoolId(activity.getApplication()));
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProClassList proClassList = new Gson().fromJson(result, ProClassList.class);
                if (proClassList != null && proClassList.getCode() == 0) {
                    activity.student = proClassList.getStudent();
                    activity.teacher = proClassList.getTeacher();
                    classFragment.paddingData();
                    teacherFragment.paddingData();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 指定班级老师，学生列表接口
     *
     * @param activity
     * @param classid
     */
    public void postTeaStuList(final ClassDetailsActivity activity, int classid) {
        String url = "";
        if (User.isTest) {
            url = BaseProtocol.HOST_BASE_TEST + "/director/classInfo";
        } else {
            url = BaseProtocol.HOST_BASE + "/director/classInfo";
        }
        RequestParams params = BaseProtocol.getRequestParams(url);

        params.addParameter("classid", classid);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProAssignTeaStuList teaStuList = new Gson().fromJson(result, ProAssignTeaStuList.class);
                if (teaStuList != null && teaStuList.getCode() == 0) {
                    activity.stuInfoEntities = null;
                    activity.teacherInfoEntities = null;
                    activity.stuInfoEntities = teaStuList.getStuInfo();
                    activity.teacherInfoEntities = teaStuList.getTeacherInfo();
                    activity.cnum = activity.stuInfoEntities.size();
                    activity.tnum = activity.teacherInfoEntities.size();
                    if (activity.adapter != null) {
                        activity.adapter.notifyDataSetChanged();
                    } else {
                        activity.paddingData();
                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
            }
        });
    }

    /**
     * 指定学校所有班级
     *
     * @param activity
     */
    public void postAllClass(final ClassDetailsActivity activity) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/schoolClass");

        params.addParameter("schoolid", User.getSchoolId(activity.getApplication()));
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProAllClassOfSchool allClassOfSchool = new Gson().fromJson(result, ProAllClassOfSchool.class);
                if (allClassOfSchool != null && allClassOfSchool.getCode() == 0) {
                    List<ProAllClassOfSchool.ClsEntity> cls = allClassOfSchool.getCls();
                    for (int i = 0; i < cls.size(); i++) {
                        activity.allClass.add(cls.get(i).getName());
                        activity.allClassId.add(cls.get(i).getCid());
                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 学生调班接口
     *
     * @param activity
     * @param studentid
     * @param classid
     */
    public void postStuChangeClass(final ChangeStuClass activity, int studentid, int classid) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/stuUpdateCls");

        params.addParameter("studentid", studentid);
        params.addParameter("classid", classid);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort(activity.getString(R.string.baocunchenggong));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.TIAOBANCHENGGONG));
                    activity.finish();
                } else {
                    HomeApplication.showToastShort(activity.getString(R.string.baocunshibai));
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort(activity.getString(R.string.baocunshibai));
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 指定学校所有班级
     *
     * @param activity
     */
    public void postAllClassTeacherId(final ChangeTeacherActivity activity, int teacherid) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/schoolClass");

        params.addParameter("schoolid", User.getSchoolId(activity.getApplication()));
        params.addParameter("teacherid", teacherid);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProAllClassOfSchool allClassOfSchool = new Gson().fromJson(result, ProAllClassOfSchool.class);
                if (allClassOfSchool != null && allClassOfSchool.getCode() == 0) {
                    activity.classlist = null;
                    activity.classlist = allClassOfSchool.getCls();
                    activity.paddingData();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 老师调班
     *
     * @param activity
     * @param teacherid
     * @param Ids
     */
    public void postTeaChangeClass(final ChangeTeacherActivity activity, int teacherid, ArrayList<TeacherFlagInAllClass> Ids) {

        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/teacherUpdateCls");

        params.addParameter("teacherid", teacherid);
        params.addBodyParameter("ids", new Gson().toJson(Ids));
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort(activity.getString(R.string.baocunchenggong));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.TIAOBANCHENGGONG));
                    activity.finish();
                } else {
                    Log.i(TAG, "onSuccess: 123456");
                    HomeApplication.showToastShort(activity.getString(R.string.baocunshibai));
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.i(TAG, "onError: " + ex);
                HomeApplication.showToastShort(activity.getString(R.string.baocunshibai));
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();
            }
        });
    }

    /**
     * 修改班级信息接口
     *
     * @param name
     * @param classId
     */
    public void changeClassName(final Context context, String name, String classId) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/ClassUpdate");

        params.addParameter("classid", classId);
        params.addParameter("name", name);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("修改班级名称成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                } else {
                    HomeApplication.showToastShort("修改班级名称失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("修改班级名称失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {

            }
        });
    }

    /**
     * 添加班级信息接口
     *
     * @param schoolid
     * @param name
     * @param leader
     * @param leadercontact
     * @param classetype
     * @param address
     * @param memo
     * @param user_name
     * @param user_account
     * @param user_gender
     * @param password
     * @param user_memo
     */
    public void addClassInfo(Context context, String schoolid, String name, String leader, String leadercontact, String classetype, String address
            , String memo, String user_name, String user_account, String user_gender, String password, String user_memo) {

        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/ClassAdd");

        params.addParameter("schoolid", schoolid);
        params.addParameter("name", name);
        params.addParameter("leader", leader);
        params.addParameter("leadercontact", leadercontact);
        params.addParameter("classetype", classetype);
        params.addParameter("address", address);
        params.addParameter("memo", memo);
        params.addParameter("user_name", user_name);
        params.addParameter("user_account", user_account);
        params.addParameter("user_gender", user_gender);
        params.addParameter("password", password);
        params.addParameter("user_memo", user_memo);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("添加班级成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                } else if (baseRequestInfo != null && baseRequestInfo.getCode() == 1) {
                    HomeApplication.showToastShort("该账号已经存在!");
                } else {
                    HomeApplication.showToastShort("添加班级失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("添加班级失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 删除老师信息
     *
     * @param teacherId
     */
    public void deleteTeacherInfo(Context context, String teacherId) {
        String url = "";
        if (User.isTest) {
            url = BaseProtocol.HOST_BASE_TEST + "/director/TeacherDel";
        } else {
            url = BaseProtocol.HOST_BASE + "/director/TeacherDel";
        }
        RequestParams params = BaseProtocol.getRequestParams(url);
//		RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/TeacherDel");

        params.addParameter("teacherid", teacherId);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("删除老师成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.SHANCHUERTONGXINXI));

                } else {
                    HomeApplication.showToastShort("删除老师失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("删除老师失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {

            }
        });
    }

    /**
     * 删除儿童信息
     *
     * @param studentId
     */
    public void deleteStudentInfo(Context context, String studentId) {
        String url = "";
        if (User.isTest) {
            url = BaseProtocol.HOST_BASE_TEST + "/director/StudentDel";
        } else {
            url = BaseProtocol.HOST_BASE + "/director/StudentDel";
        }
        RequestParams params = BaseProtocol.getRequestParams(url);
//		RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/StudentDel");

        params.addParameter("studentid", studentId);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("删除学生成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.SHANCHUERTONGXINXI));
                } else {
                    HomeApplication.showToastShort("删除学生失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("删除学生失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 部门列表
     *
     * @param activity
     * @param schoolid
     */
    public void getBumenList(final AddTeacherActivity activity, String schoolid) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/officeList");

        params.addParameter("schoolid", schoolid);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBumenList probumenlist = new Gson().fromJson(result, ProBumenList.class);
                if (probumenlist != null && probumenlist.getCode() == 0) {
                    activity.office = probumenlist.getOffice();
                    activity.bumenList = new String[probumenlist.getOffice().size()];
                    for (int i = 0; i < probumenlist.getOffice().size(); i++) {
                        activity.bumenList[i] = probumenlist.getOffice().get(i).getOffacename();
                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 部门列表
     *
     * @param activity
     * @param schoolid
     */
    public void getBumenListModifyTea(final ModifyTeacherInfo activity, String schoolid) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/officeList");

        params.addParameter("schoolid", schoolid);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBumenList probumenlist = new Gson().fromJson(result, ProBumenList.class);
                if (probumenlist != null && probumenlist.getCode() == 0) {
                    activity.office = probumenlist.getOffice();
                    activity.bumenList = new String[probumenlist.getOffice().size()];
                    for (int i = 0; i < probumenlist.getOffice().size(); i++) {
                        activity.bumenList[i] = probumenlist.getOffice().get(i).getOffacename();
                    }
                    activity.tianchongshuju();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 添加老师信息接口
     *
     * @param officeid
     * @param name
     * @param gender
     * @param birthdate
     * @param entryDate
     * @param educationType
     * @param educationUniversity
     * @param title
     * @param duty
     * @param cContact
     * @param isTopteacher
     * @param classid
     */
    public void addTeacherInfo(Context context, String officeid, String name, String gender, String birthdate, String entryDate
            , String educationType, String educationUniversity, String title, String duty, String cContact
            , String isTopteacher, String classid) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/TeacherAdd");

        params.addParameter("officeid", officeid);
        params.addParameter("name", name);
        params.addParameter("gender", gender);
        params.addParameter("birthdate", birthdate);
        params.addParameter("entryDate", entryDate);
        params.addParameter("educationType", educationType);
        params.addParameter("educationUniversity", educationUniversity);
        params.addParameter("title", title);
        params.addParameter("duty", duty);
        params.addParameter("cContact", cContact);
        params.addParameter("isTopteacher", isTopteacher);
        params.addParameter("classid", classid);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("添加老师成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.SHANCHUERTONGXINXI));
                } else {
                    HomeApplication.showToastShort("添加老师失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("添加老师失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 添加儿童信息接口
     *
     * @param schoolid
     * @param classid
     * @param name
     * @param gender
     * @param birthdate
     * @param nation
     * @param residence
     * @param address
     * @param guardian
     * @param guardianContact
     * @param isteacher
     * @param workPlace
     * @param memo
     */
    public void addStudentInfo(Context context, String schoolid, String classid, String name, String gender, String birthdate, String nation
            , String residence, String address, String guardian, String guardianContact, String isteacher, String workPlace
            , String memo) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/StudentAdd");

        params.addParameter("schoolid", schoolid);
        params.addParameter("classid", classid);
        params.addParameter("name", name);
        params.addParameter("gender", gender);
        params.addParameter("birthdate", birthdate);
        params.addParameter("nation", nation);
        params.addParameter("residence", residence);
        params.addParameter("address", address);
        params.addParameter("guardian", guardian);
        params.addParameter("guardianContact", guardianContact);
        params.addParameter("isteacher", isteacher);
        params.addParameter("workPlace", workPlace);
        params.addParameter("memo", memo);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("添加学生成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.SHANCHUERTONGXINXI));
                } else if (baseRequestInfo != null && baseRequestInfo.getCode() == 1) {
                    HomeApplication.showToastShort("当前班级有同名学生,请修改姓名!");
                } else {
                    HomeApplication.showToastShort("添加学生失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("添加学生失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 删除班级信息接口
     *
     * @param classId
     */
    public void deleteClassInfo(Context context, String classId) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/ClassDel");

        params.addParameter("classid", classId);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("删除班级成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                } else {
                    HomeApplication.showToastShort("删除班级失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("删除班级失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 获取老师信息
     *
     * @param teacherId
     */
    public void getTeacherInfo(final Activity activity, final String teacherId) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/TeacherInfo");

        params.addParameter("teacherid", teacherId);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProTeacherInfo proteacherinfo = new Gson().fromJson(result, ProTeacherInfo.class);
                if (proteacherinfo != null && proteacherinfo.getCode() == 0) {
                    ProTeacherInfo.TeacherEntity teacherEntity = proteacherinfo.getTeacher().get(0);
                    Intent intent = new Intent(activity, ModifyTeacherInfo.class);
                    Bundle mbundle = new Bundle();
                    mbundle.putParcelable("teacherentity", teacherEntity);
                    mbundle.putString("teacherId", teacherId);
                    intent.putExtras(mbundle);
                    activity.startActivity(intent);
                } else {
                    HomeApplication.showToastShort("获取老师信息失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("获取老师信息失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 修改老师信息
     *
     * @param officeid
     * @param name
     * @param gender
     * @param birthdate
     * @param entryDate
     * @param educationType
     * @param educationUniversity
     * @param title
     * @param duty
     * @param cContact
     * @param teacherid
     */
    public void modifyTeacherInfo(Context context, String officeid, String name, String gender, String birthdate, String entryDate
            , String educationType, String educationUniversity, String title, String duty, String cContact
            , String teacherid) {

        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/TeacherModify");

        params.addParameter("officeid", officeid);
        params.addParameter("name", name);
        params.addParameter("gender", gender);
        params.addParameter("birthdate", birthdate);
        params.addParameter("entryDate", entryDate);
        params.addParameter("educationType", educationType);
        params.addParameter("educationUniversity", educationUniversity);
        params.addParameter("title", title);
        params.addParameter("duty", duty);
        params.addParameter("cContact", cContact);
        params.addParameter("teacherid", teacherid);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("修改老师信息成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.SHANCHUERTONGXINXI));
                } else {
                    HomeApplication.showToastShort("修改老师信息失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("修改老师信息失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 获取儿童信息
     *
     * @param activity
     * @param studentid
     */
    public void getStudentInfo(final ClassDetailsActivity activity, final String studentid) {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(activity, "/director/StudentInfo");

        params.addParameter("studentid", studentid);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProStudentInfo prostudentinfo = new Gson().fromJson(result, ProStudentInfo.class);
                if (prostudentinfo != null) {
                    ProStudentInfo.CodeEntity codeentity = prostudentinfo.getCode().get(0);
                    Intent intent = new Intent(activity, ModifyStudentInfo.class);
                    Bundle mbundle = new Bundle();
                    mbundle.putParcelable("codeentity", codeentity);
                    mbundle.putString("classid", activity.classid + "");
                    mbundle.putString("studentid", studentid);
                    intent.putExtras(mbundle);
                    activity.startActivity(intent);
                } else {
                    HomeApplication.showToastShort("获取学生信息失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("获取学生信息失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }

    /**
     * 修改儿童信息接口
     *
     * @param schoolid
     * @param classid
     * @param name
     * @param gender
     * @param birthdate
     * @param nation
     * @param residence
     * @param address
     * @param guardian
     * @param guardianContact
     * @param workPlace
     * @param memo
     * @param studentid
     */
    public void modifyStudentInfo(Context context, String schoolid, String classid, String name, String gender, String birthdate, String nation
            , String residence, String address, String guardian, String guardianContact, String workPlace
            , String memo, String studentid) {

        RequestParams params = BasexUtilsProtocol.sendHttpRequest(context, "/director/StudentModify");
        params.addParameter("schoolid", schoolid);
        params.addParameter("classid", classid);
        params.addParameter("name", name);
        params.addParameter("gender", gender);
        params.addParameter("birthdate", birthdate);
        params.addParameter("nation", nation);
        params.addParameter("residence", residence);
        params.addParameter("address", address);
        params.addParameter("guardian", guardian);
        params.addParameter("guardianContact", guardianContact);
        params.addParameter("workPlace", workPlace);
        params.addParameter("memo", memo);
        params.addParameter("studentid", studentid);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProBaseRequestInfo baseRequestInfo = new Gson().fromJson(result, ProBaseRequestInfo.class);
                if (baseRequestInfo != null && baseRequestInfo.getCode() == 0) {
                    HomeApplication.showToastShort("修改学生信息成功!");
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.XIUGAIBANJIXINXI));
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.SHANCHUERTONGXINXI));
                } else {
                    HomeApplication.showToastShort("修改学生信息失败!");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                HomeApplication.showToastShort("修改学生信息失败!");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.cancel();

            }
        });
    }
}